package com.health.fragment.focusgroup.child;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.health.viewscontrols.FWMYDPJActivity;
import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.PersonalFileActivity.onFragmentSave;
import com.health.R;
import com.health.adapter.CheckBoxAdapter;
import com.health.adapter.RadioButtonAdapter;
import com.health.db.FDbManager;
import com.health.viewscontrols.focusgroup.ChildActivity;
import com.health.fragment.NovaFragment;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.CHILD_TCMHM_THREE2SIX;
import com.health.tablebean.CHILD_THREE2SIX_YEAR_OLD;
import com.health.tools.DateUtil;
import com.health.tools.GlobalConts;
import com.health.view.spinner.NiceSpinner;
import com.health.widget.EditTextWithDate;
import com.health.widget.MyGridView;
import com.novabluetooth.services.BluetoothConstant;
import com.novabluetooth.views.ExamHistoryActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

/**
 * 3-6岁内检查 4岁健康检查
 * 
 * @author 鹿云龙
 */
public class CheckFragment3_4 extends NovaFragment implements onFragmentSave, OnClickListener {
	private View baseView = null;
	private ARCHIVE_BASEINFO userInfo;// 基本信息
	/** 未见异常 */
	private List<BD_DD_INFO> lstyc;
	// private MyGridView mgvmianse;
	// private MyGridView mgvqianxin;
	private MyGridView mgvxinfei;

	// private MyGridView mgvpifu;
	// private MyGridView mgvkouqiang;
	private MyGridView mgvfubu;

	// 两次随访
	private MyGridView mgv_liangcisuifang;
	// 发育评估
	private MyGridView mgv_fayupinggu;
	/** 指导mgv_zhidao */
	private MyGridView mgv_zhidao;
	// 转诊建议
	// private MyGridView mgv_zzjy;
	private NiceSpinner ns_tz;
	private NiceSpinner ns_sc;
	private NiceSpinner ns_tgfypj;
	private NiceSpinner ns_sc_tz;
	private EditText et_cy;
	private EditText et_qc;

	private EditTextWithDate et_sfrq;
	private EditText et_tz;
	private EditText et_sc;
	private EditText et_sc_tz;
	// private EditText et_qt;
	private EditText ed_zzyy;
	private EditText ed_jg_ys;
	private EditText et_zyqt;
	private NiceSpinner et_sfysqm;// 随访医生
	private EditTextWithDate et_xcsfrq;

	private EditText et_hbfy;
	private EditText et_hbfx;
	private EditText et_hbws;
	private EditText et_hbqt;

	private EditText et_xhdbz;

	private static final int I_NULL = -1;

	private RadioGroup rd_zz;// 是否转诊
	private RadioButton rb_w;
	private RadioButton rb_y;
	private String str_zzId = "";
	CheckBoxAdapter rbafy;
	private EditText et_sl_l;// 左视力
	private EditText et_sl_r;// 右视力

	private int fromzy;
	private int from;

	private Button btn_tz_more;
	private Button btn_xhdb_more;
	List<EditText> lstTv;

	@Override
	public View findViews(LayoutInflater inflater) {
		baseView = inflater.inflate(R.layout.child_check_fragment3_2, null);
		userInfo = NovaApplication.getUserInfo();
		initViews();
		GlobalConts.setMaxLength(2, et_cy, et_qc);
		// GlobalConts.setMaxLength(50, et_qt);
		GlobalConts.setMaxLength(5, et_tz, et_sc, et_sc_tz);
		GlobalConts.setMaxLength(100, et_hbqt);
		GlobalConts.keep2decimal(et_tz, et_sc, et_sc_tz);

		bind();
		initData();
		return baseView;
	}

	/**
	 * 初始化布局
	 * 
	 * @author 王婷婷
	 * @date 2017年3月22日 下午2:52:45
	 */
	private void initViews() {
		// mgvmianse = (MyGridView) baseView.findViewById(R.id.mgvmianse);
		// mgvqianxin = (MyGridView) baseView.findViewById(R.id.mgvqianlu);
		mgvxinfei = (MyGridView) baseView.findViewById(R.id.mgvxinfei);

		// mgvpifu = (MyGridView) baseView.findViewById(R.id.mgvpifu);
		// mgvkouqiang = (MyGridView) baseView.findViewById(R.id.mgvkouqiang);
		mgvfubu = (MyGridView) baseView.findViewById(R.id.mgvfubu);
		mgv_liangcisuifang = (MyGridView) baseView.findViewById(R.id.mgv_liangcisuifang);
		mgv_zhidao = (MyGridView) baseView.findViewById(R.id.mgv_zhidao);

		et_sfrq = (EditTextWithDate) baseView.findViewById(R.id.etw_sfrq);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String strar = sdf.format(new Date(System.currentTimeMillis()));
		System.out.println(strar);
		et_sfrq.setText(sdf.format(new Date(System.currentTimeMillis())));
		et_tz = (EditText) baseView.findViewById(R.id.et_tz);
		et_sc = (EditText) baseView.findViewById(R.id.et_sc);
		et_sc_tz = (EditText) baseView.findViewById(R.id.et_sc_tz);
		// et_pf = (EditText) baseView.findViewById(R.id.et_pf);
		// et_tl = (EditText) baseView.findViewById(R.id.et_tl);
		// et_kq = (EditText) baseView.findViewById(R.id.et_kq);
		// et_fb = (EditText) baseView.findViewById(R.id.et_fb);
		// et_hwhd = (EditText) baseView.findViewById(R.id.et_hwhd);
		// et_fywssd = (EditText) baseView.findViewById(R.id.et_fywssd);
		// et_qt = (EditText) baseView.findViewById(R.id.et_qt);
		et_zyqt = (EditText) baseView.findViewById(R.id.et_zyqt);
		et_sfysqm = (NiceSpinner) baseView.findViewById(R.id.et_sfysqm);
		GlobalConts.doctorList(et_sfysqm);
		et_xcsfrq = (EditTextWithDate) baseView.findViewById(R.id.et_xcsfrq);

		et_hbfy = (EditText) baseView.findViewById(R.id.et_hbfy);
		et_hbfx = (EditText) baseView.findViewById(R.id.et_hbfx);
		et_hbws = (EditText) baseView.findViewById(R.id.et_hbws);
		et_hbqt = (EditText) baseView.findViewById(R.id.et_hbqt);

		et_xhdbz = (EditText) baseView.findViewById(R.id.et_xhdbz);
		et_cy = (EditText) baseView.findViewById(R.id.et_cy);
		et_qc = (EditText) baseView.findViewById(R.id.et_qc);

		ns_tz = (NiceSpinner) baseView.findViewById(R.id.ns_tz);
		ns_sc = (NiceSpinner) baseView.findViewById(R.id.ns_sc);
		ns_sc_tz = (NiceSpinner) baseView.findViewById(R.id.ns_sc_tz);
		ns_tgfypj = (NiceSpinner) baseView.findViewById(R.id.ns_tgfypj);
		et_sfrq.setBefore(true);
		et_xcsfrq.setAfter(true);

		ed_zzyy = (EditText) baseView.findViewById(R.id.ed_zzyy);
		ed_jg_ys = (EditText) baseView.findViewById(R.id.ed_jg_ys);
		rd_zz = (RadioGroup) baseView.findViewById(R.id.rd_zz);
		rb_w = (RadioButton) baseView.findViewById(R.id.rb_w);
		rb_y = (RadioButton) baseView.findViewById(R.id.rb_y);

		mgv_fayupinggu = (MyGridView) baseView.findViewById(R.id.mgv_fayupinggu);

		ed_zzyy.setEnabled(false);
		ed_jg_ys.setEnabled(false);

		// TODO 没有存储数据库的字段
		et_sl_l = (EditText) baseView.findViewById(R.id.et_sl_l);
		et_sl_r = (EditText) baseView.findViewById(R.id.et_sl_r);

		btn_tz_more = (Button) baseView.findViewById(R.id.btn_tz_more);
		btn_tz_more.setOnClickListener(this);
		btn_xhdb_more = (Button) baseView.findViewById(R.id.btn_xhdb_more);
		btn_xhdb_more.setOnClickListener(this);
	}

	RadioButtonAdapter rbaxf;
	RadioButtonAdapter rbapf;
	CheckBoxAdapter cbazhidao;
	RadioButtonAdapter rbalc;
	RadioButtonAdapter rbakq;
	RadioButtonAdapter rbafb;
	List<BD_DD_INFO> lsttzsc;
	List<BD_DD_INFO> lstFy;

	public void bind() {
		/*获取异常和未见异常值*/
		lstyc = GlobalConts.getDictionaryValue(getActivity(), "DM01-40");
		// 面色DM05-14_1
		List<BD_DD_INFO> lstms = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM05-14_1' order by cast(SORT as int) asc");
		RadioButtonAdapter rbamianse = new RadioButtonAdapter(lstms, getActivity());
		rbamianse.setOtherTextVisible(false);
		// mgvmianse.setAdapter(rbamianse);
		// 听力DM01-30
		List<BD_DD_INFO> lsttl = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM01-30' order by cast(SORT as int) asc");
		// 心肺lstyc
		rbaxf = new RadioButtonAdapter(lstyc, getActivity());
		rbaxf.setOtherTextVisible(false);
		mgvxinfei.setAdapter(rbaxf);
		// mgvpifu
		rbapf = new RadioButtonAdapter(lstyc, getActivity());
		rbapf.setOtherTextVisible(false);
		// mgvpifu.setAdapter(rbapf);
		// 口腔
		rbakq = new RadioButtonAdapter(lstyc, getActivity());
		rbakq.setOtherTextVisible(false);
		// mgvkouqiang.setAdapter(rbakq);
		// 腹部
		rbafb = new RadioButtonAdapter(lstyc, getActivity());
		rbafb.setOtherTextVisible(false);
		mgvfubu.setAdapter(rbafb);
		// 两次随访DM05-20
		List<BD_DD_INFO> lstlc = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM01-11' order by cast(SORT as int) asc");
		rbalc = new RadioButtonAdapter(lstlc, getActivity());
		rbalc.setOtherTextVisible(false);
		lstTv = new ArrayList<EditText>();
		lstTv.add(et_hbfy);
		lstTv.add(et_hbfx);
		lstTv.add(et_hbws);
		lstTv.add(et_hbqt);
		rbalc = new RadioButtonAdapter(lstlc, getActivity(), lstTv);
		rbalc.setOtherTextVisible(false);
		mgv_liangcisuifang.setAdapter(rbalc);

		// 发育评估 DM01-30
		List<BD_DD_INFO> lstfy = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM05-26_11' order by cast(SORT as int) asc");
		rbafy = new CheckBoxAdapter(getActivity(), lstfy);
		rbafy.setOtherVis(false);
		mgv_fayupinggu.setAdapter(rbafy);

		// 健康指导
		List<BD_DD_INFO> lstzd = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM05-04' order by cast(SORT as int) asc");
		List<BD_DD_INFO> listZZs_new = new ArrayList<BD_DD_INFO>();
		int size = lstzd.size();
		if (size > 0) {
			for (int i = 0; i < size; i++) {

				// DM05-04_1 科学喂养 ；DM05-04_2 合理膳食 ；DM05-04_3 生长发育
				// DM05-04_4 疾病预防;DM05-04_5 预防意外伤害;DM05-04_6 口腔保健
				// DM05-04_9 其他
				if (lstzd.get(i).getID().equals("DM05-04_2") || lstzd.get(i).getID().equals("DM05-04_3")
						|| lstzd.get(i).getID().equals("DM05-04_4") || lstzd.get(i).getID().equals("DM05-04_5")
						|| lstzd.get(i).getID().equals("DM05-04_6") || lstzd.get(i).getID().equals("DM05-04_9")) {
					listZZs_new.add(lstzd.get(i));
				}
			}
		}

		cbazhidao = new CheckBoxAdapter(getActivity(), listZZs_new);
		mgv_zhidao.setAdapter(cbazhidao);

		// 体重DM01-39
		lsttzsc = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM01-39' order by cast(SORT as int) asc");
		ns_tz.attachDataSource(getDataInfo(lsttzsc));
		// 身长DM01-39
		ns_sc.attachDataSource(getDataInfo(lsttzsc));
		ns_sc_tz.attachDataSource(getDataInfo(lsttzsc));
		// 体格发育评价DM05-03
		lstFy = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				"PARENTID = 'DM05-03' order by cast(SORT as int) asc");
		ns_tgfypj.attachDataSource(getDataInfo(lstFy));
	}

	/**
	 * 获取下拉框中需要的数据的信息
	 * 
	 * @param datas
	 * @return
	 * @author 鹿云龙
	 * @date 2015年12月16日 下午3:47:00
	 */
	private ArrayList<String> getDataInfo(List<BD_DD_INFO> datas) {
		ArrayList<String> infos = new ArrayList<String>();
		for (BD_DD_INFO bd : datas) {
			infos.add(bd.getDATAINFO());
		}
		return infos;
	}

	@Override
	public void setupView(View view) {
	}

	@Override
	public void addListener() {
		rd_zz.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if (checkedId == R.id.rb_w) {
					str_zzId = "DM01-11_1";
					ed_zzyy.setText("");
					ed_jg_ys.setText("");
					ed_zzyy.setEnabled(false);
					ed_jg_ys.setEnabled(false);

				} else if (checkedId == R.id.rb_y) {
					str_zzId = "DM01-11_2";
					ed_zzyy.setEnabled(true);
					ed_jg_ys.setEnabled(true);
				} else {
					str_zzId = "";
				}

			}
		});

	}

	@Override
	public void setData() {
		setDateCheck();

	}

	private void setDateCheck() {

		// 出牙
		GlobalConts.checkNumOrange(getActivity(), et_cy, 32, 0);
		// 出牙
		GlobalConts.checkNumOrange(getActivity(), et_qc, 32, 0);
		// 肺炎
		GlobalConts.checkNumOrange(getActivity(), et_hbfy, 99, 0);
		// 腹泻
		GlobalConts.checkNumOrange(getActivity(), et_hbfx, 99, 0);
		// 外伤
		GlobalConts.checkNumOrange(getActivity(), et_hbws, 99, 0);

	}

	public int getListIndex(String id, List<BD_DD_INFO> bds) {
		int index = 0;
		try {
			for (int i = 0; i < bds.size(); i++) {
				if (id.equals(bds.get(i).getID())) {
					index = i;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return index;
	}

	/**
	 * 字符串转换"1,2,3,4,5" --> "'1','2','3','4','5'"
	 * 
	 * @param symptom
	 * @return
	 * @author 鹿云龙
	 * @date 2015年12月19日 下午2:49:23
	 */
	public String checkedIdsSql(String symptom) {
		String[] idarr = symptom.split(",");
		String sql = "";
		for (String id : idarr) {
			sql += "'" + id + "',";
		}
		sql = sql.substring(0, sql.length() - 1);
		System.out.println(sql);
		return sql;
	}

	@Override
	public void save() {
		int age = DateUtil.getAge(userInfo.getBIRTHDAY());
		if (age < 4) {
			((ChildActivity) getActivity()).showTextDialog("儿童未满4岁，不予保存");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), et_cy, 32, 0)) {
			((ChildActivity) getActivity()).showTextDialog("出牙数不合理,最大为32颗，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), et_qc, 32, 0)) {
			((ChildActivity) getActivity()).showTextDialog("龋齿数不合理，最大为32颗，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), et_hbfy, 99, 0)) {
			((ChildActivity) getActivity()).showTextDialog("肺炎数据不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), et_hbfx, 99, 0)) {
			((ChildActivity) getActivity()).showTextDialog("腹泻数据不合理，保存失败");
			return;
		}
		if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), et_hbws, 99, 0)) {
			((ChildActivity) getActivity()).showTextDialog("外伤不合理，保存失败");
			return;
		}
		saveData();
	}

	private void saveData() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		// CHILD_THREE2SIX_YEAR_OLD
		CHILD_THREE2SIX_YEAR_OLD ctyo = new CHILD_THREE2SIX_YEAR_OLD();
		if (rb_w.isChecked()) {
			str_zzId = "DM01-11_1";
		} else if (rb_y.isChecked()) {
			str_zzId = "DM01-11_2";
		} else {
			str_zzId = "";
		}
		ctyo.setREFERRAL_ADVICE(str_zzId);
		ctyo.setREFERRAL_REASON(ed_zzyy.getText().toString());
		ctyo.setAGENCIES_DEPARTMENTS(ed_jg_ys.getText().toString());

		ctyo.setAMONG_TWO_FOLLO_NONE(rbalc.getChecked());
		ctyo.setAMONG_TWO_FOLLO_OTHER(et_hbqt.getText().toString());
		// ctyo.setARCHIVEID(aRCHIVEID);//档案编号
		// ctyo.setCREATED_BY(cREATED_BY);
		ctyo.setCREATED_DATE(new Date());
		// ctyo.setCUSTOMERID(cUSTOMERID);//客户编号
		ctyo.setAUXE_ESTIMATE_OTHER(rbafy.getCheckedIdsStr());
		String strff = et_hbfx.getText().toString();
		ctyo.setDIARRHOEA_FREQUEN(strff);
		ctyo.setFLAG("6");
		ctyo.setFOLLOWUP_DATE(new Date());
		ctyo.setFOLLOWUP_DOCTOR_SIGN(NovaApplication.getDoctorList().get(et_sfysqm.getSelectedIndex()).getUSER_ID());
		ctyo.setGUIDANCE(cbazhidao.getCheckedIdsStr());
		ctyo.setGUIDANCE_OTHER(cbazhidao.getOther());
		ctyo.setHEART_LUNG(rbaxf.getChecked());
		String strXhdb = et_xhdbz.getText().toString();
		ctyo.setHEMOGLOBIN_VALUE(strXhdb);
		// ctyo.setID(iD);
		ctyo.setIDCARD(userInfo.getIDCARD());
		// ctyo.setIS_DEL(iS_DEL);
		// ctyo.setLAST_UPDATE_BY(lAST_UPDATE_BY);
		ctyo.setLAST_UPDATE_DATE(new Date());
		// ctyo.setNAME(nAME);
		try {
			ctyo.setNEXT_FOLLOWUP_DATE(sdf.parse(et_xcsfrq.getText().toString()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		// ctyo.setOTHER(et_qt.getText().toString());
		ctyo.setPHYSICAL_AUXE_EVALUAT(lstFy.get(ns_tgfypj.getSelectedIndex()).getID());// 体格发育评价1正常
		String strfy = et_hbfy.getText().toString();
		ctyo.setPNEUMONIA_FREQUEN(strfy);

		// ctyo.setSIGHT("4");
		String strsc = et_sc.getText().toString();
		ctyo.setSTATURE(strsc);
		ctyo.setSTATURE_ANALYSIS(lsttzsc.get(ns_sc.getSelectedIndex()).getID());// 身长上中下

		/** 身长/体重 **/
		ctyo.setSTATURE_WEIGHT(et_sc_tz.getText().toString().trim());
		ctyo.setSTATURE_WEIGHT_ANALYSIS(lsttzsc.get(ns_sc_tz.getSelectedIndex()).getID());

		ctyo.setSTOMACH(rbafb.getChecked());
		String strCy = et_cy.getText().toString();
		ctyo.setTCN_LEFT(strCy);
		String strQc = et_qc.getText().toString();
		ctyo.setTDCN_RIGHT(strQc);
		String strws = et_hbws.getText().toString();
		ctyo.setTRAUMATISM_FREQUEN(strws);
		String strtz = et_tz.getText().toString();
		ctyo.setWEIGHT(strtz);
		ctyo.setWEIGHT_ANALYSIS(lsttzsc.get(ns_tz.getSelectedIndex()).getID());
		ctyo.setSIGHT(et_sl_l.getText().toString());
		ctyo.setSIGHT_RIGHT(et_sl_r.getText().toString());
		ctyo.setIS_UPDATE("Y");
		try {
			ctyo.setFOLLOWUP_DATE(sdf.parse(et_sfrq.getText().toString()));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		ctyo.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(et_sfysqm.getSelectedIndex()).getUSER_ID());
		ctyo.setLAST_UPDATE_DATE(new Date());
		if (from == 0) {
			ctyo.setCREATED_BY(userInfo.getCREATED_BY());
			ctyo.setCREATED_DATE(new Date());
			ctyo.setCREATEORG(userInfo.getCREATEORG());
			ctyo.setCREATER(userInfo.getCREATER());

			FDbManager.getInstance(getActivity()).save(ctyo);
			from = 1;
		} else {
			ctyo.setUPDATEORG(userInfo.getCREATEORG());
			ctyo.setMODIFIED(NovaApplication.getDoctorList().get(et_sfysqm.getSelectedIndex()).getUSER_ID());
			FDbManager.getInstance(getActivity()).updata(ctyo, "IDCARD='" + userInfo.getIDCARD() + "' AND FLAG='6'");
		}

		// TODO 中医药保存
		CHILD_TCMHM_THREE2SIX ctt = new CHILD_TCMHM_THREE2SIX();
		ctt.setARCHIVEID("");
		ctt.setIDCARD(userInfo.getIDCARD());
		ctt.setFOLLOWUP_DOCTOR(NovaApplication.getDoctorList().get(et_sfysqm.getSelectedIndex()).getUSER_ID());
		ctt.setFOLLOWUP_TYPE("2");
		ctt.setTCMHM_OTHER(et_zyqt.getText().toString());
		ctt.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(et_sfysqm.getSelectedIndex()).getUSER_ID());
		ctt.setLAST_UPDATE_DATE(new Date());
		
		if (fromzy == 0) {
			ctt.setCREATED_BY(userInfo.getCREATED_BY());
			ctt.setCREATED_DATE(new Date());
			ctt.setCREATEORG(userInfo.getCREATEORG());
			ctt.setCREATER(userInfo.getCREATER());
			FDbManager.getInstance(getActivity()).save(ctt);
			fromzy = 1;
		} else {

			ctt.setUPDATEORG(userInfo.getCREATEORG());
			ctt.setMODIFIED(NovaApplication.getDoctorList().get(et_sfysqm.getSelectedIndex()).getUSER_ID());
			FDbManager.getInstance(getActivity()).updata(ctt,
					"IDCARD='" + userInfo.getIDCARD() + "'  AND FOLLOWUP_TYPE='2'");
		}
		// ((ChildActivity) getActivity()).showTextDialog("保存成功");
		if (GlobalConts.TYPE_JTYS.equals(NovaApplication.getType())) {
			new AlertDialog.Builder(getActivity()).setTitle("保存成功").setMessage("进行满意度评价")
					.setPositiveButton("确定", new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {
							Intent intent = new Intent(getContext(), FWMYDPJActivity.class);
							intent.putExtra("type", "02");
							intent.putExtra("szfs", "");
							startActivity(intent);
						}
					}).show();
		} else if (GlobalConts.TYPE_GJJBGGWS.equals(NovaApplication.getType())) {
			((ChildActivity) getActivity()).showTextDialog("保存成功");
		}
	}

	private void initData() {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			CHILD_THREE2SIX_YEAR_OLD ctyo = new CHILD_THREE2SIX_YEAR_OLD();

			List<CHILD_THREE2SIX_YEAR_OLD> ctyos = FDbManager.getInstance(getActivity()).findAllByWhere(
					CHILD_THREE2SIX_YEAR_OLD.class, "IDCARD = '" + userInfo.getIDCARD() + "' AND FLAG='6'");

			if (ctyos.size() > 0) {
				ctyo = ctyos.get(ctyos.size() - 1);

				str_zzId = ctyo.getREFERRAL_ADVICE();

				if (!TextUtils.isEmpty(str_zzId)) {
					if (str_zzId.equals("DM01-11_1")) {
						rb_w.setChecked(true);
					} else if (str_zzId.equals("DM01-11_2")) {
						rb_y.setChecked(true);
					}
				}

				// adapter_zz.setChecked(str_zzId);

				ed_zzyy.setText(ctyo.getREFERRAL_REASON());
				ed_jg_ys.setText(ctyo.getAGENCIES_DEPARTMENTS());

				rbalc.setChecked(ctyo.getAMONG_TWO_FOLLO_NONE(), ctyo.getAMONG_TWO_FOLLO_OTHER());// rbalc.getChecked());
				if ("DM01-11_2".equals(ctyo.getAMONG_TWO_FOLLO_NONE())) {
					for (int i = 0; i < lstTv.size(); i++) {
						lstTv.get(i).setEnabled(true);
						lstTv.get(i).setFocusable(true);
						lstTv.get(i).setFocusableInTouchMode(true);
						lstTv.get(i).setClickable(true);
					}
				}else if ("DM01-11_1".equals(ctyo.getAMONG_TWO_FOLLO_NONE())) {
					for (int i = 0; i < lstTv.size(); i++) {
						lstTv.get(i).setEnabled(false);
						lstTv.get(i).setFocusable(false);
						lstTv.get(i).setFocusableInTouchMode(false);
						lstTv.get(i).setClickable(false);
					}
				}
				et_hbfx.setText(ctyo.getDIARRHOEA_FREQUEN());// strff.isEmpty()
				cbazhidao.setChecked(ctyo.getGUIDANCE());// cbazhidao.getCheckedIdsStr());
				cbazhidao.setOther(ctyo.getGUIDANCE_OTHER());// cbazhidao.getOther());
				rbaxf.setChecked(ctyo.getHEART_LUNG());// rbaxf.getChecked());
				String strXhdb = et_xhdbz.getText().toString();
				rbafy.setChecked(ctyo.getAUXE_ESTIMATE_OTHER());// 发育评估
				et_xhdbz.setText(ctyo.getHEMOGLOBIN_VALUE());// strXhdb.isEmpty()
				try {
					et_xcsfrq.setText(sdf.format(ctyo.getNEXT_FOLLOWUP_DATE()));// sdf.parse(et_xcsfrq.getText().toString()
				} catch (Exception e) {
					e.printStackTrace();
				}
				// et_qt.setText(ctyo.getOTHER());//
				// et_qt.getText().toString());
				ns_tgfypj.setSelectedIndex(getListIndex(ctyo.getPHYSICAL_AUXE_EVALUAT(), lstFy));// .get(ns_tgfypj.getSelectedIndex()).g
				// String strfy = et_hbfy.getText().toString();
				et_hbfy.setText(ctyo.getPNEUMONIA_FREQUEN());// strfy.isEmpty()
				et_sc.setText(ctyo.getSTATURE());// strsc.isEmpty()
				ns_sc.setSelectedIndex(getListIndex(ctyo.getSTATURE_ANALYSIS(), lsttzsc));// .get(ns_sc.getSelectedIndex()).getID())
				
				/** 身高/体重比值 **/
				et_sc_tz.setText(ctyo.getSTATURE_WEIGHT());
				ns_sc_tz.setSelectedIndex(getListIndex(ctyo.getSTATURE_WEIGHT_ANALYSIS(), lsttzsc));// .get(ns_sc.getSelectedIndex()).getID())
				
				rbafb.setChecked(ctyo.getSTOMACH());// rbafb.getChecked());
				// String strCy = et_cy.getText().toString();
				et_cy.setText(ctyo.getTCN_LEFT());// ;strCy.isEmpty()
				// String strQc = et_qc.getText().toString();
				et_qc.setText(ctyo.getTDCN_RIGHT());// strQc.isEmpty()
				// Integer.parseInt(strQc));
				// String strws = et_hbws.getText().toString();
				et_hbws.setText(ctyo.getTRAUMATISM_FREQUEN());// strws.isEmpty()
				// String strtz = et_tz.getText().toString();
				et_tz.setText(ctyo.getWEIGHT());// strtz.isEmpty()
				ns_tz.setSelectedIndex(getListIndex(ctyo.getWEIGHT_ANALYSIS(), lsttzsc));// .get(ns_tz.getSelectedIndex()).getID());
				et_hbqt.setText(ctyo.getAMONG_TWO_FOLLO_OTHER());
				et_sl_l.setText(ctyo.getSIGHT());
				et_sl_r.setText(ctyo.getSIGHT_RIGHT());
				for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
					if (ctyo.getFOLLOWUP_DOCTOR_SIGN().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
						et_sfysqm.setSelectedIndex(i);
					}
				}
			} else {
				for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
					if (userInfo.getCREATED_BY().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
						et_sfysqm.setSelectedIndex(i);
					}
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent(getActivity(), ExamHistoryActivity.class);
		int id = v.getId();
		if (id == R.id.btn_tz_more) {
			intent.putExtra("flag", BluetoothConstant.TIZHONG_TYPENAME);
			getActivity().startActivityForResult(intent, GlobalConts.RequestTizhong);
		} else if (id == R.id.btn_xhdb_more) {
			intent.putExtra("flag", "血红蛋白");
			getActivity().startActivityForResult(intent, GlobalConts.RequestXueHongDanbai);
		} else {
		}

	}

	@Override
	public void setTizhong(String value) {
		et_tz.setText(value);

	}

	@Override
	public void setXueHongDanBai(String xhdb) {
		if (!TextUtils.isEmpty(xhdb)) {
			et_xhdbz.setText(String.valueOf((int) (Double.parseDouble(xhdb) * 10)));
		}
	}
}